﻿using Colorful.Furniture.CommonManagement;
using Colorful.Furniture.ErpSupplierManagement;
using Colorful.Furniture.Extensions;
using Colorful.Furniture.PermissionManagement;
using Colorful.Furniture.SysManagement;
using Colorful.Furniture.Wrappers;
using FreeSql;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using StackExchange.Redis;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Colorful.Furniture.ErpCustomerManagement;
using Microsoft.AspNetCore.Authorization;
using Volo.Abp;
using Volo.Abp.Application.Services;
using Volo.Abp.Users;
using Volo.Abp.Validation;
using static SKIT.FlurlHttpClient.Wechat.Api.Models.UnionPromoterProductListResponse.Types.Product.Types.Coupon.Types.CouponDetail.Types;
using System.Security.AccessControl;
using Volo.Abp.Auditing;
using Essensoft.Paylink.Alipay.Domain;
using Volo.Abp.ObjectMapping;
using Colorful.Furniture.CommonDto;

namespace Colorful.Furniture.ErpInventoryManagement;

public class InventoryH5AppService : ApplicationService
{
    private readonly IBaseRepository<Inventory> _inventoryRepository;
    private readonly IBaseRepository<SysDictionary> _sysDictionaryRepository;
    private readonly IFreeSql _freeSql;
    private readonly ILogger<InventoryAppService> _logger;
    private readonly IBaseRepository<Supplier> _supplierRepository;
    private readonly FileAppService _fileAppService;
    private readonly IBaseRepository<InventoryLog> _inventoryLogRepository;
    private readonly IDatabase _redisCache;
    private readonly IBaseRepository<InventoryProduct> _inventorySkuRepository;
    private readonly IBaseRepository<InventoryWithCustomer> _inventoryWithCustomerRepository;
    private readonly ICurrentUser _currentUser;
    private readonly IBaseRepository<SysManager> _sysManagerRepository;
    private readonly IObjectMapper _objectMapper;

    public InventoryH5AppService(
        IBaseRepository<Inventory> inventoryRepository,
        IBaseRepository<SysDictionary> sysDictionaryRepository,
        IFreeSql freeSql,
        ILogger<InventoryAppService> logger,
        IBaseRepository<Supplier> supplierRepository,
        FileAppService fileAppService,
        IConnectionMultiplexer connectionMultiplexer,
        IBaseRepository<InventoryLog> inventoryLogRepository,
        IBaseRepository<InventoryProduct> inventorySkuRepository,
        IBaseRepository<InventoryWithCustomer> inventoryWithCustomerRepository,
        ICurrentUser currentUser,
        IBaseRepository<SysManager> sysManagerRepository,
        IObjectMapper objectMapper
    )
    {
        _inventoryRepository = inventoryRepository;
        _sysDictionaryRepository = sysDictionaryRepository;
        _freeSql = freeSql;
        _logger = logger;
        _supplierRepository = supplierRepository;
        _fileAppService = fileAppService;
        _inventoryLogRepository = inventoryLogRepository;
        _inventorySkuRepository = inventorySkuRepository;
        _redisCache = connectionMultiplexer.GetDatabase();
        _inventoryWithCustomerRepository = inventoryWithCustomerRepository;
        _currentUser = currentUser;
        _sysManagerRepository = sysManagerRepository;
        _objectMapper = objectMapper;
    }



    /// <summary>
    /// 获取客户端活动详情
    /// </summary>
    /// <param name="productNo">产品编码</param>
    /// <returns></returns>
    /// <exception cref="UserFriendlyException"></exception>
    public async Task<InventoryClientOutputDto> GetClientDetailAsync(string productNo)
    {
        var model = await _freeSql.Select<Inventory>()
            .Where(x => x.ProductNo == productNo)
            .ToOneAsync(x=> new InventoryClientOutputDto{});

        if (model == null)
            throw new UserFriendlyException("产品不存在");
        


        return model;
    }



}

